<template>
  <div class="maskCenter">
    <div
      id="box"
      :class="visible ? 'systemDialog' : 'systemDialog-hide'"
      style="height: 698px; width: 380px"
    >
      <div class="dialog-header" v-movew>
        <span>{{ title }}</span>
        <el-tooltip
          class="item"
          effect="dark"
          content="关闭"
          placement="top-start"
        >
          <span
            class="icon iconfont iconbiaoqianlan-guanbi close"
            @click="hide"
          ></span>
        </el-tooltip>
      </div>
      <div class="dialog-body">
        <template v-for="(comattr, index) in comattrs">
          <div class="row" v-if="comattr.rendtype != 'switch'">
            <div class="row-name">{{ comattr.label }}&nbsp;:</div>
            <el-input
              class="systemInput"
              v-if="comattr.rendtype == 'input'"
              v-model="info[comattr.attrkey]"
              clearable
            ></el-input>

            <el-autocomplete
              class="systemInput"
              style="width:100%"
              v-if="comattr.rendtype == 'inline-input' && comattr.attrkey =='autoEvent'"
              v-model="info[comattr.attrkey]"
              clearable
              :fetch-suggestions="querySearch"
            ></el-autocomplete>

            <template v-if="comattr.rendtype == 'select'">
              <!--虚拟字段允许自己编辑字段，否则调用下拉框-->
              <template v-if="comattr.attrkey == 'fieldName'">
                <el-input
                  class="systemInput"
                  v-if="info.virtual"
                  v-model.trim="info[comattr.attrkey]"
                  clearable
                ></el-input>
                <el-input
                  class="systemInput"
                  v-else
                  v-model.trim="info[comattr.attrkey]"
                  disabled
                ></el-input>
              </template>
              <el-select
                class="systemInput"
                v-else
                v-model="info[comattr.attrkey]"
                :multiple="comattr.multiple"
                collapse-tags
                clearable
                @change="selectChange($event, comattr.attrkey)"
              >
                <el-option
                  v-for="item in comattr.optionitem"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </template>
          </div>
        </template>
        <div class="switch">
          <template v-for="(comattr, index) in comattrs">
            <div class="switchbox" v-if="comattr.rendtype == 'switch'">
              <div class="row-name">{{ comattr.label }}&nbsp;:</div>
              <el-switch
                class="systemSwitch"
                v-model="info[comattr.attrkey]"
              ></el-switch>
            </div>
          </template>
        </div>
      </div>
      <div class="dialog-footer right">
        <span class="systemButtonConfirm" @click="okclick">确认</span>
        <span class="systemButtonConfirm" @click="hide">取消</span>
      </div>
    </div>
  </div>
</template>

<script>
import movew from "@/directives/winmove";
import { deepCopy } from "@/utils/public";
import { com, comconfig } from "@/system/config/cellConfigs";
export default {
  directives: { movew },
  name: "winfield",
  props: {
    title: { default: "字段属性" },
    activeItem: { default: null },
  },
  data() {
    return {
      visible: true,
      info: {},
      comattrs: null,
      autocompleteHash: {},
    };
  },
  created() {
    if (this.activeItem) {
      this.info = deepCopy(this.activeItem);
    }

    this.comattrs = deepCopy(comconfig).comattrs;
    this.comattrs.splice(0, 1);
  },
  mounted() {
    this.autocompleteHash = {};
    this.autocompleteHash["autoEvent"] = this.comattrs.find(
      (a) => a.attrkey == "autoEvent"
    ).optionitem;
    this.autocompleteHash["name"] = this.comattrs.find(
      (a) => a.attrkey == "name"
    ).optionitem;
  },
  methods: {
    hide() {
      this.visible = false;
      setTimeout(() => {
        this.$emit("close");
      }, 400);
    },
    okclick() {
      this.visible = false;
      setTimeout(() => {
        this.$set(this.info, "wfNode", null);
        this.$emit("ok", this.info);
      }, 400);
    },
    querySearch(queryString, cb) {
      let autocomplete = this.autocompleteHash["autoEvent"];
      let results = queryString
        ? autocomplete.filter(this.createFilter(queryString))
        : autocomplete;
      // 调用 callback 返回建议列表的数据
      cb(results);
    },
    createFilter(queryString) {
      return (restaurant) => {
        return (
          restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) ===
          0
        );
      };
    },
  },
};
</script>

<style scoped>
.mask {
  height: 100%;
  width: 100%;
  position: fixed;
  top: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.3);
  z-index: 99;
  display: flex;
  align-items: center;
  justify-content: center;
}

.header {
  display: flex;
  justify-content: space-between;
  height: 40px;
  line-height: 40px;
  background: var(--win-head-back-color);
  margin: 4px;
  text-align: left;
}
.header .title {
  width: calc(100% - 25px);
  height: 40px;
  line-height: 40px;
  font-size: 16px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: var(--system-page-topbar-text-color);
  margin-left: 12px;
}
.header .close {
  font-size: 12px;
  width: 12px;
  height: 12px;
  margin-right: 9px;
}

.dialog-body {
  flex-direction: row;
  color: var(--system-page-topbar-text-color);
}

.body-row {
  display: flex;
  line-height: 32px;
  height: 32px;
  margin-top: 10px;
  width: 100%;
}

/*element 输入框样式*/
>>> .el-input__inner {
  line-height: 32px;
  height: 32px;
  width: 100%px;
  border: 1px solid var(--input-border-color);
  border-radius: 4px;
  color: var(--input-text-color);
  font-size: 14px;
  font-family: Microsoft YaHei;
  font-weight: 400;
}
/*element 下拉框*/
>>> .el-input__inner:focus {
  border: 1px solid var(--input-focus-border-color);
}
/*下拉框箭头*/
>>> .el-select__caret {
  line-height: 32px;
}
>>> .el-select {
  width: 100%;
}
/*element 输入框的 focus hover样式*/
>>> .el-input__inner:focus,
>>> .el-textarea__inner:focus {
  background: var(--input-focus-back-color);
  border: 1px solid var(--input-focus-border-color);
  border-radius: 4px;
}

>>> .el-input__inner:hover,
>>> .el-textarea__inner:hover {
  background: var(--input-hover-back-color);
  border: 1px solid var(--input-focus-border-color);
}
>>> .el-textarea__inner {
  color: var(--input-text-color);
  font-size: 14px;
  font-family: Microsoft YaHei;
  font-weight: 400;
}


  .row {
		display: flex;
		line-height: 32px;
		margin-bottom: 10px;
	}
	
	.row-name {
		width: 70px;
		min-width: 70px;
		text-align: left;
		color: var(--system-form-text-color);
	}
	/*设置 element 输入框 下拉框的高度*/
	
	.row>>>.el-input__inner {
		line-height: 32px;
		height: 32px;
		color: var(--input-text-color);
		font-size:14px;
		font-family:Microsoft YaHei;
		font-weight:400;
		background: var(--page-menu-input-back-color);
	}
	
	.row>>>.el-input .el-select__caret {
		line-height: 32px;
	}
	/*element 输入框的叉叉按钮 居中*/
	
	.row>>>.el-input__icon {
		line-height: 32px;
	}
	
	.row>>>.el-color-picker__trigger {
		height: 32px;
		width: 167px;
	}
	.switch{
		display: flex;
		flex-wrap: wrap;		
	}	
	.switchbox{
		width: 114px;
		height: 32px;
		display: flex;
	}
	
.footer {
  padding-right: 20px;
  height: 60px;
  line-height: 60px;
  display: flex;
  flex-direction: row;
  justify-content: flex-end;
  margin-bottom: 20px;
}
</style>